<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    button{
      width: 60px;
      height: 30px;
      line-height: 30px;
      background-color: rgb(27, 144, 240);
      color: #fff;
      margin-bottom: 10px;
      margin-right: 10px;
      border: 0;
      border-radius: 4px;
    }
    div{
      width: 100px;
      height: 100px;
      position: absolute;
      top: 50px;
      left: 30px;
      background-color: pink;
    }
  </style>
</head>
<body>
  <button id="add">加速</button>
  <button id="stop">暂停</button>
  <div id="myDiv"></div>
</body>
<script>
  var div = document.getElementById("myDiv");
  var add = document.getElementById("add");
  var stop = document.getElementById("stop");
  var step = 3;
  var timer;
  var start = 0;
  // timerStart();

  add.onclick = function(){
    if(start == 0){
      timerStart();
      step = 3;
    }else{
      step += 3;
    }
  }

  stop.onclick = function(){
    if(start == 1){
      clearInterval(timer);
      start = 0;
    }else{
      alert("请先开始");
    }
  }

  function timerStart(){
    start = 1;
    timer = setInterval(function(){
        div.style.left = parseInt(window.getComputedStyle(div).left) + step + "px";
    },100)
  }

</script>
</html>